#include "FunkyLineTool.h"
QColor FunkyLineTool::brushColor = Qt::blue;
int FunkyLineTool::brushSize = 2;

void FunkyLineTool::mousePressEvent(QMouseEvent* event, PaintArea *ourImage)
{
                        if(ourImage->getUndoPointer() == -1)
                                 ourImage->saveUndoState();

                        ourImage->setLastPoint(event->pos());
                         ourImage->setScribbling(true);

}
void FunkyLineTool::mouseMoveEvent(QMouseEvent* event, PaintArea *ourImage)
{

       drawLineTo(event->pos(), ourImage);
}



void FunkyLineTool::drawLineTo(const QPoint &endPoint, PaintArea *ourImage)
 {
	QPoint lastPoint = ourImage->getLastPoint();
	QImage* yup = ourImage->getImage();
	QPainter painter(yup);
	const QPen pen(PaintBrush::brushColor, brushSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
	painter.setPen(pen);
         
	painter.drawLine(lastPoint, endPoint);
	//ourImage->modified = true;

	int rad = (brushSize / 2) + 2;
	ourImage->update(QRect(lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad));
	//ourImage->setLastPoint(endPoint);

        
 }
